package com.atguigu.daijia.payment.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @create: 2024/10/2
 * @author: gyhe10
 * @description: 读取配置文件中微信支付相关配置信息的属性配置类
 **/

@Data
@ConfigurationProperties(prefix = "wx.v3pay")
@Configuration
public class WxPayV3Properties {
    /**
     * 微信小程序的 appid
     */
    private String appId;
    /**
     * 微信支付商户号
     */
    private String merchantId;
    /**
     * 微信支付商户 API 密钥路径
     */
    private String privateKeyPath;
    /**
     * 微信支付商户证书序列号
     */
    private String merchantSerialNumber;
    /**
     * 微信支付商户 API v3 密钥
     */
    private String apiV3key;
    /**
     * 微信支付回调地址
     */
    private String notifyUrl;

    @Bean
    public RSAAutoCertificateConfig rsaAutoCertificateConfig() {
        return new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3key)
                .build();
    }
}
